/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx.oop;

import java.util.Random;

/**
 * <p>Project: jse2303 - C4
 * <p>Powered by webrx On 2023-07-13 17:07:39
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class C4 {
    public static void main(String[] args) {
        C4 c4 = new C4();


        String pp = c4.getPwd();
        System.out.println(pp);


        String p0 = c4.getPwd(10, 0);
        System.out.println(p0);

        String p1 = c4.getPwd(6, 1);
        System.out.println(p1);


        String p2 = c4.getPwd(16, 10);
        System.out.println(p2);
    }

    public String getPwd() {
        return getPwd(6, 0);
    }

    public String getPwd(int len, int type) {
        Random rand = new Random();
        String ps = "";
        switch (type) {
            case 0:
                String letter0 = "0123456789";
                char[] cs0 = letter0.toCharArray();
                for (int i = 0; i < len; i++) {
                    ps += String.valueOf(cs0[rand.nextInt(cs0.length)]);
                }
                break;
            case 1:
                String letter1 = "abcdefghijklmnopqrstuvwxyz";
                char[] cs1 = letter1.toCharArray();
                for (int i = 0; i < len; i++) {
                    ps += String.valueOf(cs1[rand.nextInt(cs1.length)]);
                }
                break;

            case 2:
                String letter2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                char[] cs2 = letter2.toCharArray();

                for (int i = 0; i < len; i++) {
                    ps += String.valueOf(cs2[rand.nextInt(cs2.length)]);
                }
                break;

            case 3:
                String letter3 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                char[] cs3 = letter3.toCharArray();
                for (int i = 0; i < len; i++) {
                    ps += String.valueOf(cs3[rand.nextInt(cs3.length)]);
                }
                break;
            default:
                String letter4 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*()<>,.~`[]{}-+*&^%$#@!?/";
                char[] cs4 = letter4.toCharArray();
                for (int i = 0; i < len; i++) {
                    ps += String.valueOf(cs4[rand.nextInt(cs4.length)]);
                }
                break;
        }
        return ps;
    }
}
